#include <stdio.h>
#include <stdlib.h>	
#include <string.h>

void get_memory(char *p)
{
	p = (char *)malloc(100);
}

int main()
{
	char *str = NULL;
	get_memory(str);
	strcpy(str, "xiaozhi");		// segmentation fault
	
	printf("%s\n", str);
}

#if 0
/*
 * intel
 */
0000000000001169 <get_memory>:
    1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp
    116e:	48 89 e5             	mov    %rsp,%rbp
    1171:	48 83 ec 10          	sub    $0x10,%rsp
    1175:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    1179:	bf 64 00 00 00       	mov    $0x64,%edi
    117e:	e8 ed fe ff ff       	callq  1070 <malloc@plt>
    1183:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    1187:	90                   	nop
    1188:	c9                   	leaveq 
    1189:	c3                   	retq   

000000000000118a <main>:
    118a:	f3 0f 1e fa          	endbr64 
    118e:	55                   	push   %rbp
    118f:	48 89 e5             	mov    %rsp,%rbp
    1192:	48 83 ec 10          	sub    $0x10,%rsp
    1196:	48 c7 45 f8 00 00 00 	movq   $0x0,-0x8(%rbp)
    119d:	00 
    119e:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    11a2:	48 89 c7             	mov    %rax,%rdi
    11a5:	e8 bf ff ff ff       	callq  1169 <get_memory>
    11aa:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    11ae:	48 ba 78 69 61 6f 7a 	movabs $0x69687a6f616978,%rdx
    11b5:	68 69 00 
    11b8:	48 89 10             	mov    %rdx,(%rax)
    11bb:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    11bf:	48 89 c7             	mov    %rax,%rdi
    11c2:	e8 99 fe ff ff       	callq  1060 <puts@plt>
    11c7:	b8 00 00 00 00       	mov    $0x0,%eax
    11cc:	c9                   	leaveq 
    11cd:	c3                   	retq   
    11ce:	66 90                	xchg   %ax,%ax


/*
 * arm
 */
000000000040064c <get_memory>:
  40064c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400650:	910003fd 	mov	x29, sp
  400654:	f9000fa0 	str	x0, [x29, #24]
  400658:	d2800c80 	mov	x0, #0x64                  	// #100
  40065c:	97ffffa9 	bl	400500 <malloc@plt>
  400660:	f9000fa0 	str	x0, [x29, #24]
  400664:	d503201f 	nop
  400668:	a8c27bfd 	ldp	x29, x30, [sp], #32
  40066c:	d65f03c0 	ret

0000000000400670 <main>:
  400670:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400674:	910003fd 	mov	x29, sp
  400678:	f9000fbf 	str	xzr, [x29, #24]
  40067c:	f9400fa0 	ldr	x0, [x29, #24]
  400680:	97fffff3 	bl	40064c <get_memory>
  400684:	f9400fa0 	ldr	x0, [x29, #24]
  400688:	90000001 	adrp	x1, 400000 <_init-0x4c0>
  40068c:	911d8021 	add	x1, x1, #0x760
  400690:	f9400021 	ldr	x1, [x1]
  400694:	f9000001 	str	x1, [x0]
  400698:	f9400fa0 	ldr	x0, [x29, #24]
  40069c:	97ffffa9 	bl	400540 <puts@plt>
  4006a0:	52800000 	mov	w0, #0x0                   	// #0
  4006a4:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4006a8:	d65f03c0 	ret
  4006ac:	00000000 	.inst	0x00000000 ; undefined


#endif

